//
//  AppDelegate.swift
//  WeiBoItem
//
//  Created by jss on 16/4/16.
//  Copyright © 2016年 jss. All rights reserved.
//

import UIKit
import AFNetworking

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    //测试数据转模型成功
//    let vc = JSSEmoticonkeyboardViewModel.EmoticonkeyboardSharedViewModel
//     print(vc.defaultEmoticons.count)//108
//     print(vc.emojiEmoticons.count)//80
//     print(vc.lxhEmoticons.count)//40
//     print(vc.allEmoticons)//测试已经取到数据
//
    
    AFNetworkActivityIndicatorManager.sharedManager().enabled = true
    
    //测试接档
    //去沙盒读取用户信息
//    
//    let path = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last! as NSString) .stringByAppendingPathComponent("accountArchive")
//    //解档返回数据
//    let backDate = NSKeyedUnarchiver.unarchiveObjectWithFile(path) as? JSSUserAccont
//
//    print(backDate)
    
    //注册切换根控制器的通知
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "changedViewController:", name: JSSChangeRootVC, object: nil)

        setupAppearance()
        
        //创建window
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        //把系统的TabarControl设置为window的根控制器
        //window?.rootViewController = MainTabBarController()
    
    
    if JSSUserAccountModel.sharedAccontModel.isLogin {
        //把welcom设置为window的根控制器
        window?.rootViewController = JSSWelcomViewController()
        
    }else {
        //把系统的TabarControl设置为window的根控制器
        window?.rootViewController = MainTabBarController()
    }
    
    //    测试欢迎页面的
    //    window?.rootViewController = JSSWelcomViewController()
    
        //让window成为应用程序的主窗口并且可见
        window?.makeKeyAndVisible()
        
        return true
    }
    
    
    func changedViewController(info:NSNotification){
        
        print("切换控制器")
        
        //根据接收的通知判断切换相应的控制器
        if info.object == nil {
            
            //把系统的TabarControl设置为window的根控制器
            window?.rootViewController = MainTabBarController()
        }else {
            //把welcom设置为window的根控制器
            window?.rootViewController = JSSWelcomViewController()
            
        }
        
    }
    
    //设置导航栏的统一外观对象
   private func setupAppearance() {
        
        let navigationBar = UINavigationBar.appearance()
        
        navigationBar.tintColor = UIColor.orangeColor()
    
    navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont.systemFontOfSize(20)]
  
    
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

